#include "mainwindow.h"
#include "ui_mainwindow.h"
#include"dialog.h"
#include<QMessageBox>
#include<QPushButton>
#include<QDebug>
#include<QColorDialog>
#include<QColor>
#include<QFileDialog>
#include<QFontDialog>
#include<QInputDialog>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    Dialog* dialog=new Dialog(this);
    dialog->setWindowTitle("窗口消息");
    dialog->setAttribute(Qt::WA_DeleteOnClose);
   // dialog->show(); 非模态对话框
    dialog->exec();//模态对话框
}

void MainWindow::on_pushButton_2_clicked()
{
    QMessageBox* messagebox=new QMessageBox(this);
    messagebox->setText("这是第二个对话框");
    messagebox->setIcon(QMessageBox::Warning);
    messagebox->setWindowTitle("这是第二个对话框的标题");
    QPushButton* button=new QPushButton("接受",messagebox);
    messagebox->addButton(button,QMessageBox::AcceptRole);
//    messagebox->setStandardButtons(QMessageBox::Ok|QMessageBox::Save|QMessageBox::Cancel);
    messagebox->resize(500,400);
    messagebox->exec();
    messagebox->setAttribute(Qt::WA_DeleteOnClose);
}

void MainWindow::on_pushButton_3_clicked()
{
    int result=QMessageBox::warning(this,"对话框标题","对话框文本",QMessageBox::Ok|QMessageBox::Cancel);
    if(result==QMessageBox::Ok) {
        qDebug()<<"Ok";
    }else if(result==QMessageBox::Cancel) {
        qDebug()<<"Canle";
    }
}

void MainWindow::on_pushButton_4_clicked()
{
    QColor color=QColorDialog::getColor(QColor(0,255,0),this,"选择颜色");
    char style[1024]={0};
    sprintf(style,"background-color:rgb(%d,%d,%d);",color.red(),color.green(),color.blue());
    this->setStyleSheet(style);

}

void MainWindow::on_pushButton_5_clicked()
{
   QString filepath= QFileDialog::getOpenFileName(this);
   qDebug()<<filepath;
}

void MainWindow::on_pushButton_6_clicked()
{
    QString filepath= QFileDialog::getSaveFileName(this);
    qDebug()<<filepath;
}

void MainWindow::on_pushButton_7_clicked()
{
    bool ok=false;
    QFont font=QFontDialog::getFont(&ok);

    ui->pushButton_7->setFont(font);
}

void MainWindow::on_pushButton_8_clicked()
{
    int result=QInputDialog::getInt(this,"整数输入对话框","请输入一个整数");
    qDebug()<<result;
}

void MainWindow::on_pushButton_9_clicked()
{
    double result=QInputDialog::getDouble(this,"浮点数输入对话框","请输入一个浮点数");
    qDebug()<<result;
}

void MainWindow::on_pushButton_10_clicked()
{
    QStringList items;
    items.push_back("123");
    items.push_back("124");
    items.push_back("125");
    items.push_back("1216");
    QString item=QInputDialog::getItem(this,"条目输入对话框","请输入一个条目",items);
    qDebug()<<item;
}
